package com.warm.thread.manager;

import org.noear.solon.annotation.Component;
import org.noear.solon.core.bean.LifecycleBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 确保应用退出时能关闭后台线程
 *
 * @author warm
 */
@Component
public class ShutdownManager implements LifecycleBean {
    private static final Logger logger = LoggerFactory.getLogger("sys-user");

    /**
     * 停止异步执行任务
     */
    private void shutdownAsyncManager() {
        try {
            logger.info("====关闭后台任务任务线程池====");
            AsyncManager.me().shutdown();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }

    @Override
    public void start() throws Throwable {

    }

    @Override
    public void stop() throws Throwable {
        shutdownAsyncManager();
        LifecycleBean.super.stop();
    }

    @Override
    public void afterInjection() throws Throwable {
        LifecycleBean.super.afterInjection();
    }
}
